//
//  XPhotoCollectionSectionHeader.m
//  XPhotoLibraryKit
//
//  Created by Wu,Xinting on 2018/3/20.
//

#import "XPhotoCollectionSectionHeader.h"

@interface XPhotoCollectionSectionHeader ()

@property (nonatomic, strong) UILabel *bannerLabel;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation XPhotoCollectionSectionHeader

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.frame = CGRectMake(4.f, 0, frame.size.width - 8.f, frame.size.height);
        [self addSubview:self.titleLabel];
        [self addSubview:self.bannerLabel];
    }
    return self;
}

- (void)refresh {
    self.titleLabel.text = self.title;
    if (self.bannerString) {
        self.bannerLabel.hidden = NO;
        self.bannerLabel.text = self.bannerString;
        self.bannerLabel.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 40);
        self.titleLabel.frame = CGRectMake(4.f, self.bannerLabel.bounds.size.height, self.bounds.size.width - 4.f, 40);
    } else {
        self.bannerLabel.hidden = YES;
        self.titleLabel.frame = CGRectMake(4.f, 0, self.bounds.size.width - 4.f, 40);
    }
}

#pragma mark - Get&Set
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    }
    return _titleLabel;
}

- (UILabel *)bannerLabel {
    if (!_bannerLabel) {
        _bannerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _bannerLabel.textAlignment = NSTextAlignmentCenter;
        _bannerLabel.font = [UIFont boldSystemFontOfSize:18];
        _bannerLabel.textColor = [UIColor blueColor];
    }
    return _bannerLabel;
}

@end
